# -*- coding: utf-8 -*-
"""
Created on Thu Dec  3 10:04:33 2020

@author: andrew
"""

import pytest
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('./diver/chromedriver')

try:
    driver.get("http://www.python.org")
    driver.set_window_size(1190, 690)
    time.sleep(1)
    print(driver.title)
    # print(driver.page_source)
    # <button type="submit" name="submit" id="submit" class="search-button" title="Submit this Search" tabindex="3">
    #                                     GO
    #                                 </button>
    # 以下代码基于http://www.python.org页面的以上html
    element = driver.find_element_by_id("submit")
    # element = driver.find_element_by_name("submit")
    # element = driver.find_element_by_class_name("search-button")
    print("id:",element.get_attribute("id"))
    print("name:",element.get_property("name"))
    print("class:",element.get_attribute("class"))
    print("Text:",element.text)
    element.click()
    driver.back()
    time.sleep(2)

    # <a href="//docs.python.org/3/tutorial/introduction.html#lists">More about defining functions in Python 3</a>
    # 以下代码基于http://www.python.org页面的以上html，由于页面滚动注意运行代码时间
    # element = driver.find_element_by_link_text("More about defining functions in Python&nbsp;3")
    element = driver.find_element_by_partial_link_text("More about defining functions")
    print("href:", element.get_property("href"))
    # element.click()

    time.sleep(1)
    # driver.quit()
except Exception as e:
    print(e)
finally:
    driver.quit()